cmake_minimum_required(VERSION 2.8)

PROJECT(ATOMISM)
INCLUDE(CTest)

if(COMMAND cmake_policy)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

CONFIGURE_FILE(config.h.cmake config.h)

SET(COVERAGE 0 CACHE BOOL "if one activate code coverage option for tests")
SET(PYTHON   1 CACHE BOOL "if one python binding (need python libraries)")
SET(VTK   1 CACHE BOOL "if one compile VTK files for 3D visualization")
SET(BAYES  0 CACHE BOOL "if one compile the Bayesian stuffs (needs QUESO)")

IF( COVERAGE )
   MESSAGE( STATUS "Enable code coverage for tests (-DCOVERAGE=0 to desactivate)")
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -Wall -W -fprofile-arcs -ftest-coverage")
   SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
   SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
   SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
ELSEIF( NOT COVERAGE )
   MESSAGE( STATUS "Disable code coverage for tests (-DCOVERAGE=1 to activate)")
   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wall -fPIC")
ENDIF( COVERAGE )

IF( PYTHON )
   MESSAGE( STATUS "Python binding activated (-DPYTHON=0 to desactivate)")
ELSEIF( NOT PYTHON )
   MESSAGE( STATUS "Python binding desactivated (-DPYTHON=0 to activate)")
ENDIF( PYTHON )

IF( VTK )
   MESSAGE( STATUS "Compiles VTK files for 3D visualization (-DVTK=0 to desactivate)")
   FIND_PACKAGE(VTK REQUIRED)
ELSEIF( NOT VTK )
   MESSAGE( STATUS "Does not compile VTK files for 3D visualization (-DVTK=1 to activate)")
ENDIF( VTK )

IF( BAYES )
   MESSAGE( STATUS "Compiles the Bayes directory files for inverse probleme and UQ (-DBAYES=0 to desactivate)")
ELSEIF( NOT BAYES )
   MESSAGE( STATUS "Does not compile the Bayes directoryfor inverse probleme and UQ (-DBAYES=1 to activate)")
ENDIF( BAYES )

MESSAGE( STATUS "The installation is realized in ${CMAKE_INSTALL_PREFIX}  (-DCMAKE_INSTALL_PREFIX=/my/directory to change it)")

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})

SET( LAUNCHER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/atomism.cpp)
file(WRITE ${LAUNCHER_FILE} "" )
#-------------------------------------------------------------------------------------------------
#------------------ Set compiler name for build directory's name ---------------------------------
#-------------------------------------------------------------------------------------------------

SET(COMPILER Intel )
IF( CMAKE_COMPILER_IS_GNUCC )
   SET(COMPILER GnuCC )
ENDIF( CMAKE_COMPILER_IS_GNUCC )
IF( CMAKE_COMPILER_IS_GNUCXX )
   SET(COMPILER GnuCXX )
ENDIF( CMAKE_COMPILER_IS_GNUCXX )

SET(LIBRARY_OUTPUT_PATH 
    ${CMAKE_CURRENT_SOURCE_DIR}/build/libs${COMPILER} CACHE PATH
    "Single directory for all libraries")
  
SET( CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/build/ )
  
MESSAGE( STATUS "The libraries are collected in ${LIBRARY_OUTPUT_PATH}")



#-------------------------------------------------------------------------------------------------
#------------------ include sub directories of ATOMISM  source files  
#-------------------------------------------------------------------------------------------------


ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/src/Base )
GET_DIRECTORY_PROPERTY (ATOMISM_BASE_INCLUDE_DIRS DIRECTORY ./src/Base DEFINITION ATOMISM_BASE_INCLUDE_DIRS )
GET_DIRECTORY_PROPERTY (ATOMISM_BASE_LIBRARIES DIRECTORY ./src/Base DEFINITION ATOMISM_BASE_LIBRARIES )

ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/src/Molecule) 
GET_DIRECTORY_PROPERTY (ATOMISM_MOLECULE_INCLUDE_DIRS DIRECTORY ./src/Molecule DEFINITION ATOMISM_MOLECULE_INCLUDE_DIRS )
GET_DIRECTORY_PROPERTY (ATOMISM_MOLECULE_LIBRARIES DIRECTORY ./src/Molecule DEFINITION ATOMISM_MOLECULE_LIBRARIES )

ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/src/Math) 
GET_DIRECTORY_PROPERTY (ATOMISM_MATH_INCLUDE_DIRS DIRECTORY ./src/Math DEFINITION ATOMISM_MATH_INCLUDE_DIRS )
GET_DIRECTORY_PROPERTY (ATOMISM_MATH_LIBRARIES DIRECTORY ./src/Math DEFINITION ATOMISM_MATH_LIBRARIES )


IF( BAYES )
   ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/src/Bayes) 
   GET_DIRECTORY_PROPERTY (ATOMISM_BAYES_INCLUDE_DIRS DIRECTORY ./src/Bayes DEFINITION ATOMISM_BAYES_INCLUDE_DIRS )
   GET_DIRECTORY_PROPERTY (ATOMISM_BAYES_LIBRARIES DIRECTORY ./src/Bayes DEFINITION ATOMISM_BAYES_LIBRARIES )
ENDIF( BAYES )

ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/MyWorks) 
GET_DIRECTORY_PROPERTY (ATOMISM_MYWORK_INCLUDE_DIRS DIRECTORY ./MyWorks DEFINITION ATOMISM_MYWORK_INCLUDE_DIRS )
GET_DIRECTORY_PROPERTY (ATOMISM_MYWORK_LIBRARIES DIRECTORY ./MyWorks DEFINITION ATOMISM_MYWORK_LIBRARIES )


SET( ATOMISM_INCLUDE ${ATOMISM_BASE_INCLUDE_DIRS}
		     ${ATOMISM_MOLECULE_INCLUDE_DIRS}
		     ${ATOMISM_MATH_INCLUDE_DIRS}
		     ${ATOMISM_BAYES_INCLUDE_DIRS}
		     ${ATOMISM_MYWORK_INCLUDE_DIRS}
		     )

SET( ATOMISM_LIBRARIES  ${ATOMISM_BASE_LIBRARIES}
			${ATOMISM_MOLECULE_LIBRARIES} 
			${ATOMISM_MATH_LIBRARIES} 
			${ATOMISM_BAYES_LIBRARIES}
			${ATOMISM_MYWORK_LIBRARIES}
    )
#-------------------------------------------------------------------------------------------------
#------------------ compile library ATOMISM --------------------------------------------------------
#-------------------------------------------------------------------------------------------------


include_directories( ${ATOMISM_INCLUDE})

message(STATUS "\n----------From CMakeLists.txt----------")
message(STATUS "Libraries: ${ATOMISM_LIBRARIES}")
message(STATUS "Includes: ${ATOMISM_INCLUDE}")

add_library ( atomism   SHARED src/atomism.cpp )
             
SET_TARGET_PROPERTIES( atomism PROPERTIES COMPILE_FLAGS -fPIC )
SET_TARGET_PROPERTIES( atomism PROPERTIES COMPILE_FLAGS -O3 )
set_target_properties(atomism PROPERTIES  SUFFIX .so)
TARGET_LINK_LIBRARIES( atomism ${ATOMISM_LIBRARIES} ${VTK_LIBRARIES})

#-------------------------------------------------------------------------------------------------
#------------------ Working directory
#-------------------------------------------------------------------------------------------------

#ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/MyWorks )

#-------------------------------------------------------------------------------------------------
#------------------ Tests 
#-------------------------------------------------------------------------------------------------


ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/tests_cpp/H2 )
add_test (test_H2  ${CMAKE_CURRENT_SOURCE_DIR}/tests_cpp/H2/test_H2 )
#set_tests_properties (test_1D_LAM_Classique_Quantique PROPERTIES PASS_REGULAR_EXPRESSION 
#"kin=4.07714 ; Qclass(300)=2.17136 ; Qquant(300)=2.15281 ; QquantFromDos(300)=2.16919 ; DOSclass(300)=4.14359 ; DOSquant(300)=20")
ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/tests_cpp/N4 )
add_test (test_N4  ${CMAKE_CURRENT_SOURCE_DIR}/tests_cpp/N4/test_N2 )

#add_test (test_1D_LAM_Classique_Quantique  ${CMAKE_CURRENT_SOURCE_DIR}/tests_cpp/test_0/test_0)
#set_tests_properties (test_1D_LAM_Classique_Quantique PROPERTIES PASS_REGULAR_EXPRESSION 
#"kin=4.07714 ; Qclass(300)=2.17136 ; Qquant(300)=2.15281 ; QquantFromDos(300)=2.16919 ; DOSclass(300)=4.14359 ; DOSquant(300)=20")


#ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/tests_cpp/test_1 )

#add_test (test_SAM  ${CMAKE_CURRENT_SOURCE_DIR}/tests_cpp/test_1/test_1)
#set_tests_properties (test_SAM PROPERTIES PASS_REGULAR_EXPRESSION 
#"Qho(1500)=0.0140749 ; QhoDos(1500)=0.0140516 ; Qao(1500)=0.0157492 ;  QaoDos(1500)=0.0157492 ; ")


#ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/tests_cpp/test_2 )

#add_test (test_python  ${CMAKE_CURRENT_SOURCE_DIR}/tests_cpp/test_2/test_2)


#lcov --no-checksum --directory . --capture --output-file app.info
#genhtml --output-dir ./coverage app.info

#INSTALL(TARGETS atomism DESTINATION /home/chico/Projects/python/atomism )

